<?php

namespace app\controller\v1;

use app\model\OrderModel;
use app\validate\OrderValidate;
use app\validate\WarehouseValidate;

class Warehouse extends System
{

    /**
     * Notes: 仓库查看的订单列表
     * User: chenLei
     * Date: 10/26/25 15:25:45
     * @return \think\response\Json
     */
    public function orderList()
    {
        $orderModel = new OrderModel();
        $res = $orderModel->list($this->params);

        return $this->successJson('ok', $res);
    }


    /**
     * Notes: 订单详情¬
     * User: chenLei
     * Date: 10/26/25 15:42:50
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function orderInfo()
    {
        $validate = new WarehouseValidate();
        if (!$validate->scene('orderInfo')->check($this->params)) {
            return $this->errorJson($validate->getError());
        }

        $orderModel = new OrderModel();
        $res = $orderModel->info($this->params);

        if ($res === false) {
            return $this->errorJson($orderModel->getError());
        }

        return $this->successJson($res);

    }


    /**
     * Notes: 仓库确认领料
     * User: chenLei
     * Date: 10/27/25 10:55:05
     * @return \think\response\Json
     */
    public function receivedMaterials()
    {
        $validate = new WarehouseValidate();
        if (!$validate->scene('receivedMaterials')->check($this->params)) {
            return $this->errorJson($validate->getError());
        }
        $orderModel = new OrderModel();
        $res = $orderModel->receivedMaterials($this->params);

        if ($res === false) {
            return $this->errorJson($orderModel->getError());
        }

        return $this->successJson();
    }


    /**
     * Notes: 生产完成
     * User: chenLei
     * Date: 10/27/25 11:59:06
     * @return \think\response\Json
     */
    public function productionCompletedInbound()
    {
        $validate = new WarehouseValidate();
        if (!$validate->scene('productionCompletedInbound')->check($this->params)) {
            return $this->errorJson($validate->getError());
        }
        $orderModel = new OrderModel();
        $res = $orderModel->productionCompletedInbound($this->params);

        if ($res === false) {
            return $this->errorJson($orderModel->getError());
        }

        return $this->successJson();
    }

}